// *******************************************************重写RadioGroup****************************************
Ext.override(Ext.form.RadioGroup, {
			getValue : function() {
				var v;
				if (this.rendered) {
					this.items.each(function(item) {
								if (!item.getValue())
									return true;
								v = item.getRawValue();
								return false;
							});
				} else {
					for (var k in this.items) {
						if (this.items[k].checked) {
							v = this.items[k].inputValue;
							break;
						}
					}
				}

				return v;
			},
			setValue : function(v) {
				if (this.rendered)
					this.items.each(function(item) {
								item.setValue(item.getRawValue() == v);
							});
				else {
					for (var k in this.items) {
						this.items[k].checked = this.items[k].inputValue == v;
					}
				}

			}
		});

		
		/** ************************************************ 横向分析 ******************************************************************* */
				
function tbfx_row_fun(fbh, data_grid, fsdate, fedate, query_value) {

	var col_Jthtwb = Ext.data.Record.create([ {
					name : 'fid',
					mapping : 'fid',
					type : 'string'
				},{
					name : 'fbh',
					mapping : 'fbh',
					type : 'string'
				}, {
					name : 'fcoldesc',
					mapping : 'fcoldesc',
					type : 'string'
				}, {
					name : 'fcolname',
					mapping : 'fcolname',
					type : 'string'
				} ]);

				var col_ds = new Ext.data.Store({
					reader : new Ext.data.JsonReader({
						totalProperty : 'totalProperty',
						root : 'root'
					}, col_Jthtwb),
					idProperty : 'threadid',
					remoteSort : true,
					url : 'headInfo!queryHeadInfoTbfx.do'

				});

				col_ds.load({
					params : {
						'fbh' : fbh
					}
				});


				//定义勾选框，不需要可不必定义
				var col_sm = new Ext.grid.CheckboxSelectionModel({
					singleSelect : true
				});

				//定义列
				var col_colM = new Ext.grid.ColumnModel([ col_sm, new Ext.grid.RowNumberer(),//增加自动编号，不需要可不必定义
				    {
						header : '名称',
						dataIndex : 'fcoldesc',
						width : 180,
						sortable : false
					} ]);

				//生成表格
				var col_grid = new Ext.grid.GridPanel({
					closable : false,
					region : 'center',
					height : 350,
					autoWidth : true,
					cm : col_colM,
					ds : col_ds,
					sm : col_sm,
					listeners : {
						rowdblclick : function(grid, row) { //双击打开
							var col_record = col_grid.getSelectionModel().getSelected();
							if (col_record) {
								
							}
						}
					}
				});
					
	var btn_cancel_design = new Ext.Button({
		text : '关闭',
		iconCls : 'sy-reset',
		handler : function() {
			design_table_window.close();
		}
	});
	
	var tree_nav = new Ext.Panel({
		title : '报表树',
		region : 'west',
		split : true,
		layoutConfig:{
            animate:true
        },
		width : 240,
		layout : 'fit',
		autoScroll : false,
		collapsible : true,
		items : [ col_grid ]
	});	
 		    
	
	var btn_gcfx = new Ext.Button({
		text : '构成分析',
		iconCls : 'sy-chart_pie',
		handler : function() {
			var chart_data = "<?xml version='1.0' encoding='GB2312'?>";
			var col_record = col_grid.getSelectionModel().getSelected();
			chart_data += "<graph baseFontSize='12' xAxisName='" + "report" + "' "
						+ " caption='" + col_record.data.fcoldesc + "构成比对分析图' "
						+ " chartLeftMargin='0' baseFont='宋体' chartRightMargin='10' showExportDataMenuItem='1' useRoundEdges='1' exportEnabled='1' exportAtClient='1' exportHandler='FCExporter' exportAction='download' exportDialogMessage='正在导出，请稍候...' " 
						+ " exportFileName='" + col_record.data.fcoldesc + "' "
						+ " exportFormats='PDF=导出PDF文件|PNG=导出PNG文件|JPG=导出JPG文件' "
						+ " yAxisName='" + col_record.data.fcoldesc + "' canvasBorderThickness='1' numberPrefix=''>";
						
			var view_record = data_grid.getSelectionModel().getSelected();
			var array = data_grid.getSelectionModel().getSelections();
			var name_temp = "";
			var value_temp = "";
			Ext.each(array, function(view_record) {
				name_temp = view_record.get("f1");
				value_temp = view_record.get(col_record.data.fcolname);
				//随机生成颜色代码
				chart_data += "<set color='" + (Math.random()*0xffffff<<0).toString(16) + "' name='" + name_temp + "' value='" + value_temp + "'/>";
				//alert(view_record.get("f1"));
			});
			chart_data += "</graph>";
			
			var myChart = new FusionCharts(
						"../../flash/baseCharts/Doughnut3D.swf",
						"myChartId", "600", "400", "0", "1");
				//myChart.setDataXML("<?xml version='1.0' encoding='GB2312'?><graph baseFontSize='12' xAxisName='月度' caption='2008年月度销售业绩图表'  chartLeftMargin='0' baseFont='宋体' chartRightMargin='10' showExportDataMenuItem='1' useRoundEdges='1' exportEnabled='1' exportAtClient='1' exportHandler='FCExporter' exportAction='download' exportDialogMessage='正在导出，请稍候...' exportFileName='图表' exportFormats='PDF=导出PDF文件|PNG=导出PNG文件|JPG=导出JPG文件' yAxisName='销售额' canvasBorderThickness='1' numberPrefix='￥'> <set color='F6C11F' name='一月' value='1161534.41'/><set color='8EBB07' name='二月' value='1428912.69'/><set color='02BEBE' name='三月' value='882182.43'/><set color='048F8F' name='四月' value='1255166.68'/><set color='D74B4B' name='五月' value='863471.76'/><set color='904990' name='六月' value='1532418.17'/><set color='5C882B' name='七月' value='1539662.29'/><set color='B5AD0A' name='八月' value='1745698.81'/><set color='018ED6' name='九月' value='1357742.98'/><set color='9E0B10' name='十月' value='1226967.13'/><set color='A6BCC1' name='十一月' value='1720995.86'/><set color='24BF3D' name='十二月' value='1491760.59'/></graph>")
  			myChart.setDataXML(chart_data);
  			myChart.render("chart_divs");
			
		}
	});
	
	var btn_qsfx = new Ext.Button({
		text : '趋势分析',
		iconCls : 'sy-chart_line',
		handler : function() {
			var jgts_str = Ext.get("fjgts_id_col").dom.value;
			if(jgts_str == null || jgts_str == "") {
				
			} 
			
			var view_record = data_grid.getSelectionModel().getSelected();
			var array = data_grid.getSelectionModel().getSelections();
			var name_temp = "";
			var value_temp = "";
			Ext.each(array, function(view_record) {
				name_temp += view_record.get("f1") + ",";
			});
			
			Ext.Ajax.request({
				url : 'headInfo!produceChartQsfxCol.do',
				params : {
					"fbh" : fbh,
					"fquery_str" : query_value,
					"fstartDate" : fsdate,
					"fendDate" : fedate,
					"fjgts" :jgts_str,
					"fcol_str" : name_temp
				},
				success : function() {
					tree_op.root.reload();
					top.Ext.Msg.alert('', '删除报表成功！');
				},
				failure : function() {
					Ext.Msg.show({
						title : '错误提示',
						msg : '删除报表失败！',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR
					});
				}
			});
		}
	});
	
	
    var design_rightPanel = new Ext.Panel({
    	region: "center",
		layout:'fit',
		border : true,
		//title : fbh,
	    //collapsible : true,
		autoScroll: true,
		margins:'0 0 0 0',
		tbar : [ btn_gcfx, '-', '间隔天数:', {
					xtype : 'numberfield',
					name : 'fcoldesc',
					id : 'fjgts_id_col',
					width : 40
				}, btn_qsfx, '-', btn_cancel_design],
		html : '<div id ="chart_divs" align="center" style="overflow:auto;"> </div>'
	});
 			
	var design_table_window = new Ext.Window(
	{
		width : document.body.clientWidth, //自适应宽度
		height : document.body.clientHeight,
		//maximizable: true,
		layout : 'border',
		title : '横向比对分析',
		iconCls : 'sy-win-flag',
		modal : true,
		items : [ tree_nav, design_rightPanel ]
	});
	design_table_window.show();

} // end 


